﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Aggregate
{
    class Program
    {
        static void Main(string[] args)
        {

            var numbers = GetArray(5);

            var result = (from n in numbers
                          select n).Aggregate(
                            (total, next) =>
                            {
                                return total * next;
                            });
            

            Console.WriteLine("5的阶乘为:{0}", result);//返回120，也就是1*2*3*4*5


        }

        static IEnumerable<int> GetArray(int max)
        {
            List<int> result = new List<int>(max);
            for (int i = 0; i < max; i++)
            {
                result.Add(i + 1);
            }

            return result;

        }
    }
}
